package leetcode.tree;

public class morrisIn {
    public static class Node{
        public int value;
        public Node left;
        public Node right;

        public Node(Node left,Node right) {
            this.left = left;
            this.right = right;
        }
    }
    public static void process(Node head){
        if (head == null){
            return;
        }
        Node cur = head;
        Node mostRight = null;
        while (cur!=null){
            mostRight = cur.left;
            while (mostRight.right!=null && mostRight.right!=cur){
                mostRight=mostRight.right;
            }
            if (mostRight.right == null){
                mostRight.right = cur;
                cur = cur.left;
                continue;
            }else {
                mostRight.right = null;
            }
            System.out.println(cur.value + "");
            cur = cur.right;
        }
    }
}
